package com.xiaoyu.util2;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class FilePathUtil {
	public static String commandPath(String file) {
		return file.replaceAll("\\\\", "/").replaceAll("//", "/");
	}

	public static String getParentPath(String file) {
		if (file.indexOf("/") != -1) {
			String temp = null;
			Pattern p = Pattern.compile("[/]+");
			Matcher m = p.matcher(file);
			int i = 0;
			while (m.find()) {
				temp = m.group(0);
				i += temp.length();
			}
			String parent = "";
			for (int j = 0; j < i; ++j) {
				parent = parent + "../";
			}
			return parent;
		}
		return "./";
	}
}